package com.tzxs.pay.util;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

public class ViewDialog extends DialogFragment {

    private int layoutId = 0;//布局id

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        if (window == null) {
            return;
        }
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        //重新设置宽度
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        layoutParams.width = (int) (window.getWindowManager().getDefaultDisplay().getWidth() * 0.75);
        layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(layoutParams);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(layoutId, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        showListener.onShow(view);
    }

    //设置布局id
    public void setLayoutId(int id) {
        this.layoutId = id;
    }

    //监听view接口
    public interface OnViewListener {
        void onShow(View view);
    }

    //监听事件
    private OnViewListener showListener;


    public void showViewListener(OnViewListener showListener) {
        this.showListener = showListener;
    }


}
